package com.example.demo.pattern.mixpattern.entity.goose.adapter;

import com.example.demo.pattern.mixpattern.entity.duck.QuackAble;
import com.example.demo.pattern.mixpattern.entity.goose.impl.Goose;
import com.example.demo.pattern.mixpattern.observer.Observable;
import com.example.demo.pattern.mixpattern.observer.Observer;

//鹅进行鸭叫用的适配器
public class GooseAdapter implements QuackAble {
    private final Observable observable;
    private final Goose goose;

    public GooseAdapter(Goose goose) {
        this.goose = goose;
        observable = new Observable(this);
    }

    @Override
    public void quack() {
        goose.honk();
        notifyObservers();
    }

    @Override
    public void registerObserver(Observer observer) {
        observable.registerObserver(observer);
    }

    @Override
    public void notifyObservers() {
        observable.notifyObservers();
    }
}
